<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <style type="text/css">
    .el-main{
        position: absolute;
        top: 70px;
        bottom: 0px;
        left: 200px;
        right: 10px;
        padding: 0;
    }
    </style>
</head>
<body class="hold-transition skin-purple sidebar-mini">
    <div id="app">
        <el-container>
            <el-header  class="main-header" style="height:70px;">
                <nav class="navbar navbar-static-top" :class=''>
                    <!-- Logo -->
                    <a href="#" class="logo" style="text-align:center">
                        <span class="logo-lg"><img src="../img/logo.png"></span>
                    </a>
                    <div class="right-menu">
                        <span class="help"><i class="fa fa-exclamation-circle" aria-hidden="true"></i>帮助</span>
                        <el-dropdown class="avatar-container right-menu-item" trigger="click">
                            <div class="avatar-wrapper">
                                <img src="../img/user2-160x160.jpg" class="user-avatar">
                                {{username}}
                            </div>
                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item divided>
                                    <span style="display:block;">修改密码</span>
                                </el-dropdown-item>
                                <el-dropdown-item divided>
                                        <span style="display:block;"><a href="/logout.do"> 退出</a></span>
                                    </el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                    </div>
                </nav>
            </el-header>
            <el-container>
                <el-aside width="200px">
                    <el-menu>
                        <el-submenu v-for="menu in newMenuList" :index="menu.path">
                            <template slot="title">
                                <i class="fa" :class="menu.icon"></i>
                                {{menu.title}}
                            </template>
                            <template v-for="child in menu.children">
                                <el-menu-item :index="child.path">
                                    <a :href="child.linkUrl" target="right">{{child.title}}</a>
                                </el-menu-item>
                            </template>
                        </el-submenu>
                    </el-menu>
                </el-aside>
                <el-container>
                    <iframe name="right" class="el-main" src="ordersetting.html" width="100%" height="580px" frameborder="0"></iframe>
                </el-container>
            </el-container>
        </el-container>
    </div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    new Vue({
        el: '#app',
        data:{
            //List<Menu>
            menuList:[
                {
                    "path": "1",
                    "title": "工作台",
                    "icon":"fa-dashboard",
                    "children": []
                },
                {
                    "path": "2",
                    "title": "会员管理",
                    "icon":"fa-user-md",
                    "children": [
                        {
                            "path": "/2-1",
                            "title": "会员档案",
                            "linkUrl":"member.html",
                            "children":[]
                        },
                        {
                            "path": "/2-2",
                            "title": "体检上传",
                            "children":[]
                        },
                        {
                            "path": "/2-3",
                            "title": "会员统计",
                            "linkUrl":"all-item-list.html",
                            "children":[]
                        },
                    ]
                },
                {
                    "path": "3",
                    "title": "预约管理",
                    "icon":"fa-tty",
                    "children": [
                        {
                            "path": "/3-1",
                            "title": "预约列表",
                            "linkUrl":"ordersettinglist.html",
                            "children":[]
                        },
                        {
                            "path": "/3-2",
                            "title": "预约设置",
                            "linkUrl":"ordersetting.html",
                            "children":[]
                        },
                        {
                            "path": "/3-3",
                            "title": "套餐管理",
                            "linkUrl":"setmeal.html",
                            "children":[]
                        },
                        {
                            "path": "/3-4",
                            "title": "检查组管理",
                            "linkUrl":"checkgroup.html",
                            "children":[]
                        },
                        {
                            "path": "/3-5",
                            "title": "检查项管理",
                            "linkUrl":"checkitem.html",
                            "children":[]
                        },
                    ]
                },
                {
                    "path": "4",
                    "title": "健康评估",
                    "icon":"fa-stethoscope",
                    "children":[
                        {
                            "path": "/4-1",
                            "title": "中医体质辨识",
                            "linkUrl":"all-medical-list.html",
                            "children":[]
                        },
                    ]
                },
                {
                    "path": "5",     //菜单项所对应的路由路径
                    "title": "统计分析",     //菜单项名称
                    "icon":"fa-heartbeat",
                    "children":[//是否有子菜单，若没有，则为[]
                        {
                            "path": "/5-1",
                            "title": "会员数量折线图",
                            "linkUrl":"report_member.html",
                            "children":[]
                        },
                        {
                            "path": "/5-2",
                            "title": "套餐预约占比饼图",
                            "linkUrl":"report_setmeal.html",
                            "children":[]
                        },
                        {
                            "path": "/5-3",
                            "title": "运营数据统计",
                            "linkUrl":"report_business.html",
                            "children":[]
                        },{
                            "path": "/5-4",
                            "title": "男女会员比例分析",
                            "linkUrl":"sexProportion.html",
                            "children":[]
                        },{
                            "path": "/5-5",
                            "title": "会员年龄段占比分析",
                            "linkUrl":"ageGroup.html",
                            "children":[]
                        },
                    ]
                },
                {
                    "path": "6",
                    "title": "系统设置",
                    "icon":"fa-users",
                    "children": [
                        {
                            "path": "/6-1",
                            "title": "权限管理",
                            "linkUrl":"permission.html",
                            "children":[]
                        },
                        {
                            "path": "/6-2",
                            "title": "菜单管理",
                            "linkUrl":"menu.html",
                            "children":[]
                        },
                        {
                            "path": "/6-3",
                            "title": "角色管理",
                            "linkUrl":"role.html",
                            "children":[]
                        },
                        {
                            "path": "/6-4",
                            "title": "用户管理",
                            "linkUrl":"user.html",
                            "children":[]
                        },
                    ]
                }
            ],
            menus:[],
            newMenuList:[],
            username:null//用户名
        },
        created:function () {
            this.initData();
        },
        methods: {
            //初始化数据
            initData() {
                //获取用户名
                axios.get('/user/getUsername.do').then(res => {
                    if (res.data.flag) {
                        this.username = res.data.data;

                        //存储:sessionStorage只是在一个页面生效,安全
                        var sessionStorage = window.sessionStorage;
                        sessionStorage.setItem("username",JSON.stringify(this.username));

                        //获取改用户关联的menu
                        axios.get('/permission/getMenuByName.do?username=' + this.username).then(res => {
                            if (res.data.flag) {
                                this.menus = res.data.data;
                                //获取改用户所有拥有的操作菜单页面的权限
                                axios.get('/permission/getPermissionByName.do?username=' + this.username).then(res => {
                                    if (res.data.flag) {
                                        //存储全局数据
                                        var permissions = res.data.data;
                                        sessionStorage.setItem("permissions",JSON.stringify(permissions));                                        this.initPages();
                                    } else {
                                        this.error("初始化失败")
                                    }
                                });
                            } else {
                                this.error("初始化失败")
                            }
                        });
                    }
                })
            },
                //初始化页面
                initPages(){
                    //获取展示页面
                    var menus = this.menus;
                    this.newMenuList = this.menuList;
                    var list = this.newMenuList;
                    for (let menu of list) {
                        var childrens = menu.children;
                        if (childrens.length != 0) {
                            for (let children of childrens) {
                                var inArray = this.isInArray(menus,children.title);
                                if (!inArray){
                                    var index = childrens.indexOf(children);
                                    childrens[index] = 1;
                                }
                            }
                        }
                    }
                    this.chain(list);
                    this.newMenuList = list;
                },
            //判断数组中包含某个元素
            isInArray(arr,value){
                for(var i = 0; i < arr.length; i++){
                    if(value === arr[i]){
                        return true;
                    }
                }
                return false;
            },
            //判断值为1
            judgeNull(value){
                if (value == 1) {
                    return true
                }
                return false
            },
        //    循环遍历
            chain(list){
                for (let menu of list) {
                    //    判断是否含有子页面
                    if (menu.children.length == 0) {
                        var indexOf = list.indexOf(menu);
                        list.splice(indexOf, 1);
                        this.chain(list)
                    }else{
                        var childrens = menu.children;
                        for (let children of childrens){
                            if (this.judgeNull(children)) {
                                var of = childrens.indexOf(children);
                                childrens.splice(of,1);
                                this.chain(list)
                            }
                        }
                    }
                }
            }
        }
    }),
    $(function() {
            var wd = 200;
            $(".el-main").css('width', $('body').width() - wd + 'px');
    });
</script>
</html>
